package com.gxa.modules.app.outpatient.medical.service.impl;

import com.gxa.modules.app.outpatient.medical.dto.*;
import com.gxa.modules.app.outpatient.medical.mapper.AppItemsMapper;
import com.gxa.modules.app.outpatient.medical.mapper.AppMedicalRecordMapper;
import com.gxa.modules.app.outpatient.medical.mapper.AppPackageMapper;
import com.gxa.modules.app.outpatient.medical.mapper.AppPackageTypeMapper;
import com.gxa.modules.app.outpatient.medical.service.MedicalService;
import com.gxa.modules.model.entity.hospital.MedicalRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MedicalServiceImpl implements MedicalService {

    @Autowired
    private AppPackageTypeMapper packageTypeMapper;

    @Autowired
    private AppPackageMapper packageMapper;

    @Autowired
    private AppItemsMapper itemsMapper;

    @Autowired
    private AppMedicalRecordMapper medicalRecordMapper;


    @Override
    public List<PackageTypeDto> queryAll() {
        List<PackageTypeDto> packageTypes = this.packageTypeMapper.queryAll();
        return packageTypes;
    }

    @Override
    public List<PackageDto> queryById(Integer id) {
        List<PackageDto> packageDtos = this.packageMapper.queryById(id);
        return packageDtos;
    }

    @Override
    public List<ItemsDto> queryByPackageId(Integer id) {
        List<ItemsDto> itemsDtos = this.itemsMapper.queryAppById(id);
        return itemsDtos;
    }

    @Override
    public Integer add(MedicalRecord medicalRecord) {
        this.medicalRecordMapper.add(medicalRecord);
        Integer id = this.medicalRecordMapper.queryId();
        int mon = (int)Math.round(medicalRecord.getSum());
        this.medicalRecordMapper.reduceMoney(mon);
        return id;
    }


    public Double queryByPaintId(Integer id){
        Double aDouble = this.medicalRecordMapper.queryById(id);
        return aDouble;
    }

    @Override
    public MedicalRecordDto queryByRecordId(Integer id) {
        MedicalRecordDto medicalRecordDto = this.medicalRecordMapper.queryByRecordId(id);
        return medicalRecordDto;
    }

    @Override
    public List<RecordDto> selectByPatientId(Integer id, Date StartTime, Date EndingTime) {
        List<RecordDto> recordDtos = this.medicalRecordMapper.queryByPatientId(id, StartTime, EndingTime);
        return recordDtos;
    }

    public ReportInformationDto selectMaxById(Integer id){
        ReportInformationDto reportInformationDto = this.medicalRecordMapper.queryMax(id);
        return reportInformationDto;
    }

    @Override
    public List<ItemDto> selectByReportId(Integer id) {
        List<ItemDto> strings = this.packageMapper.queryByPatientId(id);
        return strings;
    }

    @Override
    public List<ItemsResultDto> queryByIndicatorId(Integer id,Integer reportId) {
        List<ItemsResultDto> itemsDtos = this.itemsMapper.queryByIndicatorId(id,reportId);
        return itemsDtos;
    }
}
